package com.hezhi.framework.dao.common;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import com.hezhi.framework.dao.common.Extractor;

public interface BaseDao extends Serializable{
	/**
	 * query the first record,then extractor the record to return a Object
	 * &lt;T&gt;
	 * 
	 * @param sql
	 * @param extractor
	 * @param args
	 * @return
	 */
	<T> T get(final String sql, final Extractor<T> extractor,
			Object... args);

	/**
	 * query all records,then extract record to object &lt;T&gt;, return a
	 * List&lt;T&gt;
	 * 
	 * @param sql
	 * @param extractor
	 * @param args
	 * @return
	 */
	<T> List<T> list(String sql, Extractor<T> extractor, Object... args);

	/**
	 * query a page of records,then extract record to object &lt;T&gt;, return a List&lt;T&gt; <br/>
	 * the size of page is DaoImpl.DEFAULT_PAGE_SIZE
	 * 
	 * @param <T>
	 * @param pageNo
	 *            begin with 0
	 * @param sql
	 * @param extractor
	 * @param args
	 * @return
	 */
	<T> List<T> page(String sql, int pageNo, Extractor<T> extractor,
			Object... args);

	/**
	 * query a page of records, then extract record to object &lt;T&gt;, return
	 * a List&lt;T&gt;
	 * 
	 * @param <T>
	 * @param pageNo
	 *            begin with 0
	 * @param pageSize
	 * @param sql
	 * @param extractor
	 * @param args
	 * @return
	 */
	<T> List<T> page(String sql,int pageNo, int pageSize, 
			Extractor<T> extractor, Object... args);

	/**
	 * update,insert,delete
	 * 
	 * @param sql
	 * @param args
	 * @return
	 */
	int execute(String sql, Object... args);

	/**
	 * batch Execute
	 * 
	 * @param sql
	 * @param batchArgs
	 * @return
	 */
	int[] batchExecute(String sql, Object[]... batchArgs);

	/**
	 * get sequence form DB by sequence name.
	 * 
	 * @param sequenceName
	 * @return
	 */
	long sequence(String sequenceName);

	/**
	 * the keys of the Map just is the argument keys.
	 * <br /> the value mapped with the key is extracted form the record related with the key of DB.
	 * @param <K>
	 * @param <V>
	 * @param sql
	 * @param extractor
	 * @param keys
	 *            the last argument
	 * @param args
	 * @return
	 */
	<K, V> Map<K, V> map(String sql, Extractor<V> extractor,
			Collection<K> keys, Object... args);

}
